<?php
class PageBar
{

    public $rows = 10;
    public $page;
    public $rowcounts;
    public $url;

    public function  getbar()
    {
        $pageall = intval($this->rowcounts%$this->rows==0)?intval($this->rowcounts/$this->rows):intval($this->rowcounts/$this->rows)+1;

        $bar = "";

        $bar.="<ul class=\"pagination fixed\">";

        if($this->page+1>$pageall&&$this->page!=1){
            $prev = $this->page-1;
            $bar.= "<li class=\"first\"><a href=\"{$this->url}/page/{$prev}\">‹ 上一页</a></li>";
            $bar.= "<li>页数 {$this->page} / {$pageall}</li>";
            $bar.= "<li class=\"last\">下一页 ›</li>";
        }else if($pageall==0){
            $bar.= "<li class=\"first\">‹ 上一页</li>";
            $bar.= "<li>页数 {$this->page} / {$pageall}</li>";
            $bar.= "<li class=\"last\">下一页 ›</li>";
        }else{

            if($this->page == 1){
                $bar.= "<li class=\"first\">‹ 上一页</li>";
                $bar.= "<li>页数 {$this->page} / {$pageall}</li>";
                $nxt = $this->page+1;
                if($this->page == $pageall){
                    $bar.= "<li class=\"last\">下一页 ›</li>";
                }else{
                    $bar.= "<li class=\"last\"><a href=\"{$this->url}/page/{$nxt}\">下一页 ›</a></li>";
                }

            }else{
                $prev = $this->page-1;
                $bar.= "<li class=\"first\"><a href=\"{$this->url}/page/{$prev}\">‹ 上一页</a></li>";
                $bar.= "<li>页数 {$this->page} / {$pageall}</li>";
                $nxt = $this->page+1;
                if($this->page == $pageall){
                    $bar.= "<li class=\"last\">下一页 ›</li>";
                }else{
                    $bar.= "<li class=\"last\"><a href=\"{$this->url}/page/{$nxt}\">下一页 ›</li>";
                }
            }
        }
        $bar.="</ul>";

        return $bar;
    }

}